package nl.aronmandos.myhealth.api;

import nl.aronmandos.myhealth.bll.ExampleBLL;
import nl.aronmandos.myhealth.dal.ExampleDAL;
import nl.aronmandos.myhealth.dal.IExampleDAL;
import nl.aronmandos.myhealth.domain.Example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.ContextConfiguration;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * Root resource (exposed at "myresource" path)
 */

@Controller
@Path("example")
public class ExampleAPI {
    @Autowired
    private IExampleDAL exampleDAL;

    //private ExampleBLL exampleBLL = new ExampleBLL();

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/")
    public List<Example> getExamples() {
        try {
            return exampleDAL.getExamples();
        } catch (Exception e) {
            e.printStackTrace();
        }
        //TODO authorize
        //TODO validate any input
        return null;
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/{id}")
    public Example getExample(@PathParam("id") Integer id) {
        System.out.println("[Example]getExample id: "+1);
        //TODO authorize
        //TODO validate any input

        try {
            return exampleDAL.getExample(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
